﻿using EasyBuyShop.DAL;
using EasyBuyShop.Models;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;

namespace EasyBuyShop.Controllers
{
    public class HomeController : Controller
    {
        private readonly ILogger<HomeController> logger;

        public HomeController(ILogger<HomeController> logger)
        {
            this.logger = logger;
        }

        public IActionResult Index()
        {
            CategoryDal categoryDal = new CategoryDal();
            SubCategoryDal subCategoryDal = new SubCategoryDal();
            ProductDal productDal = new ProductDal();
            var categories = categoryDal.GetCategories();
            var subCategories = subCategoryDal.GetSubCategories();
            var topNew100Product = productDal.GetTopNew100();
            var topDiscount3Product = productDal.GetTopDisCount3();
            ViewData["Categories"] = categories;
            ViewData["SubCategories"] = subCategories;
            ViewData["TopNew100"] = topNew100Product;
            ViewData["TopDiscount3"] = topDiscount3Product;
            var username = HttpContext.Session.GetString("username");
            var realName = HttpContext.Session.GetString("realname");
            ViewData["Username"] = username;
            ViewData["RealName"] = realName;
            return View();
        }

        public IActionResult Privacy()
        {
            return View();
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}